package com.example.mvp.mvppromote.base;

import android.app.Activity;
import android.content.Context;

import com.example.mvp.mvppromote.utils.LoadingDialog;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by wty on 2016/6/27 0027.
 */
public class BasePresenter<T extends IBaseView> implements IPresenter {
    private T mView;
    protected CompositeSubscription compositeSubscription;
    private LoadingDialog loadingDialog;
    public BasePresenter(T view) {
        this.mView = view;
    }

    protected void unSubscribe() {
        if (compositeSubscription != null) {
            compositeSubscription.unsubscribe();
        }
    }
    public void showDialog(Context context){
        loadingDialog=new LoadingDialog((Activity) context);
        loadingDialog.show();
    }
    public void closeDialog(){
        if (loadingDialog!=null){
            loadingDialog.close();
        }
    }
    protected void addSubscribe(Subscription subscription) {
        if (compositeSubscription == null) {
            compositeSubscription = new CompositeSubscription();
        }
        compositeSubscription.add(subscription);
    }

    @Override
    public void unsubcrible() {
        this.mView = null;
        unSubscribe();
    }
}
